home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++,comp.lang.c
- Path: netcom.com!marnold
- From: marnold@netcom.com (Matt Arnold)
- Subject: Re: Performance: C vs. C++
- Message-ID: <marnoldDL5z3s.24I@netcom.com>
- Organization: NETCOM On-line Communication Services (408 261-4700 guest)
- References: <30F6BAAC.12B5@iastate.edu> <4da9pn$a45@news.bridge.net>
- Date: Sun, 14 Jan 1996 09:16:40 GMT
- Sender: marnold@netcom6.netcom.com
-
- David Byrden <100101.2547@compuserve.com> writes:
-
-
- >Steve;
-
- >C and C++ are so similar that I would expect similar code to produce
- >almost identical performance. However, note that while virtual functions
- >cause overhead when you use them, exceptions in most present compilers can
- >cause overhead *at every function call*.
-
- Well...
-
- Borland C++ only generates the required exception overhead if the function
- contains exception constructs (try, throw, etc.). A "normal" function that
- does not contain such constructs has no extra code.
-
- For example, with C++ exceptions fully enabled (and with other functions
- in the same translation unit clearly getting extra exception code---via
- examination of C++-to-assembly output), a simple function like this...
-
- void Nothing()
- {
- }
-
- ...generates a single instruction (a ret). Granted, such a function could
- be recognized and treated as a special case by the compiler, but my
- experience with Borland C++ in general proves otherwise. With Borland C++,
- you do not pay for C++ exceptions at every function call. And, I'd actually
- be surprised if many other compilers are less efficient than this and
- require some kind of exception overhead in every single function.
-
-
- And on your other point...
-
- By the way, virtual functions are usually implemented as a call-though-
- function-pointer. To get the same functionality offered by C++ virtual
- functions in C, you'd probably use the same approach (a function pointer
- whose address is set to call the appropriate version of a function). In
- this sense, C++ is no less efficient than C.
-
-
- Regards,
- -------------------------------------------------------------------------
- Matt Arnold | | ||| | |||| | | | || ||
- marnold@netcom.com | | ||| | |||| | | | || ||
- Boston, MA | 0 | ||| | |||| | | | || ||
- 617.389.7384 (h) 617.576.2760 (w) | | ||| | |||| | | | || ||
- C++, MIDI, Win32/95 developer | | ||| 4 3 1 0 8 3 || ||
- -------------------------------------------------------------------------
-
-
-